package com.dwxt.community.service;

import com.dwxt.community.dao.*;
import com.dwxt.community.entity.*;
import org.springframework.beans.factory.annotation.*;
import org.springframework.stereotype.*;

import java.util.*;

/**
 * 上门回收人员信息
 */
@Service
public class RecoveryOndoorService {

    @Autowired
    private RecoveryOndoorMapper recoveryOndoorMapper;
    @Autowired
    private CommunityService communityService;

    public Integer createRecord(RecoveryOndoor recoveryOndoor){
       Community community = communityService.selectById(recoveryOndoor.getCommunityId());
       recoveryOndoor.setCommunityName(community.getCommunityName());
       return recoveryOndoorMapper.insertSelective(recoveryOndoor);
    }

    public Integer updateRecord(RecoveryOndoor recoveryOndoor){
        Community community = communityService.selectById(recoveryOndoor.getCommunityId());
        recoveryOndoor.setCommunityName(community.getCommunityName());
        return recoveryOndoorMapper.updateByPrimaryKeySelective(recoveryOndoor);
    }

    public Integer deleteRecord(Integer id){
        return recoveryOndoorMapper.deleteByPrimaryKey(id);
    }

    public List<RecoveryOndoor> selecPersontList(){
        RecoveryOndoorExample recoveryOndoorExample = new RecoveryOndoorExample();
        List<RecoveryOndoor> recoveryOndoors = recoveryOndoorMapper.selectByExample(recoveryOndoorExample);
        if (recoveryOndoors.size()>0){
            return recoveryOndoors;
        }

        return null;
    }

    public List<RecoveryOndoor> selecPersontListByName(String communityName) {
        RecoveryOndoorExample recoveryOndoorExample = new RecoveryOndoorExample();
        recoveryOndoorExample.createCriteria().andCommunityNameLike(communityName);
        List<RecoveryOndoor> recoveryOndoors = recoveryOndoorMapper.selectByExample(recoveryOndoorExample);
        if (recoveryOndoors.size()>0){
            return recoveryOndoors;
        }
        return null;
    }

    public RecoveryOndoor selectById(Integer id) {
       return recoveryOndoorMapper.selectByPrimaryKey(id);
    }
}
